package com.minyifang.wcspf.work.ui.user.activities;

import android.widget.TextView;

import com.google.gson.Gson;
import com.minyifang.wcspf.R;
import com.minyifang.wcspf.common.base.BaseMvpActivity;
import com.minyifang.wcspf.common.md5.SafeUtils;
import com.minyifang.wcspf.common.utils.ToastHelper;
import com.minyifang.wcspf.work.model.HttpRespond;
import com.minyifang.wcspf.work.ui.Global;
import com.minyifang.wcspf.work.ui.user.model.MessageBean;
import com.minyifang.wcspf.work.ui.user.presenter.MessagePresenter;
import com.minyifang.wcspf.work.ui.user.view.MessageView;

import butterknife.BindView;
import butterknife.OnClick;

public class MessageActivity extends BaseMvpActivity<MessageView, MessagePresenter> implements MessageView {

    @BindView(R.id.tv_order_msg)
    TextView tv_order_msg;
    @BindView(R.id.tv_notify_msg)
    TextView tv_notify_msg;
    @BindView(R.id.tv_sys_msg)
    TextView tv_sys_msg;

    @Override
    protected int setContentLayoutRes() {
        return R.layout.activity_message;
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void initData() {

    }

    @Override
    public void onResume() {
        super.onResume();
        mPresenter.getMessageData();
    }

    @OnClick(R.id.ll_trade_msg)
    void ll_trade_msg() {
        MessageListActivity.start(this, "2");
    }

    @OnClick(R.id.ll_notice_msg)
    void ll_notice_msg() {
        MessageListActivity.start(this, "1");
    }

    @OnClick(R.id.ll_system_msg)
    void ll_system_msg() {
        MessageListActivity.start(this, "0");
    }

    @Override
    protected MessagePresenter createPresenter() {
        return new MessagePresenter();
    }

    @Override
    public void showLoadingView() {
        showLoadingDialog();
    }

    @Override
    public void hideLoadingView() {
        hideLoadingDialog();
    }

    @Override
    public void onNetworkError() {

    }

    @Override
    public void showMessageData(HttpRespond<String> respond) {
        if (respond.result == 1) {
            if (respond.isaes == 1) {
                MessageBean bean = new Gson().fromJson(SafeUtils.decrypt(respond.data), MessageBean.class);
                tv_order_msg.setText(bean.getOrderMsg());
                tv_notify_msg.setText(bean.getMsg());
                tv_sys_msg.setText(bean.getSysMsg());
            }
        } else if (respond.result == -1) {
            Global.reLogin(this);
        } else
            ToastHelper.getInstance(this).showWarn(respond.message);
    }
}
